<?php
include("include/config.inc.php");

$pageName = 'party';

if($_SESSION['s_userType'] == 'User')
{
   $authorization = "NoAccess";
   foreach($selUsermenuArr as $value)
   {
      if(in_array($pageName, $value))
      {
        $authorization = "Access";
        break;
      }
      else 
      {
        $authorization = "NoAccess";    
      }
   }
   if($authorization == "NoAccess")
   {
     header("location:index.php");
   }
}

$i = 0;
$partyId   	= isset($_REQUEST['partyId']) ? $_REQUEST['partyId'] : 0;
$partyName 		= "";
$isEdit 	= 0;
$viewArr  = array();
  
if(isset($_POST['insertBtn']))
{
  if(isset($_POST['updatePartyId']) && $_POST['updatePartyId'] > 0)
  {
    $updateMarkoQuery = "UPDATE party
       											SET partyName = '".$_POST['partyName']."'
	      									WHERE partyId   = ".$_POST['updatePartyId'];
    $updateMarkoQueryResult = mysql_query($updateMarkoQuery);
    if(!$updateMarkoQueryResult)
      die("Update Query Not Inserted : ".mysql_error());
    else
      header("Location:party.php");  
  }
  else
  {
  	$insertQueryParty = "INSERT INTO party (partyName)
                          VALUE('".$_POST['partyName']."')";
    $insertQueryPartydResult = mysql_query($insertQueryParty);
    if(!$insertQueryPartydResult)
    
    die("Insert Query Not Inserted : ".mysql_error());
    else
    {
      header("Location:party.php");
    }
  }
}

$msg            = "Record Not Found";
$partyDataArray = array();
if(isset($_POST['insertBtn']))
$i = 0;
$editPartyId   = 0;
$editPartyName = "";

$selectParty = "SELECT partyId,partyName
                  FROM party
              ORDER BY partyName";
$selectPartyResult = mysql_query($selectParty);
while($partydRow = mysql_fetch_array($selectPartyResult))
{
	$partyDataArray[$i]['partyId']     = $partydRow['partyId'];
	$partyDataArray[$i]['partyName']   = $partydRow['partyName'];
	if($partydRow['partyId']== $partyId)
	{
	  $editPartyId   = $partydRow['partyId'];
		$editPartyName = $partydRow['partyName'];
	}
	$i++;
}

include("./bottom.php");
$smarty->assign("partyDataArray",$partyDataArray);
$smarty->assign("msg",$msg);
$smarty->assign("i",$i);
$smarty->assign("partyId",$partyId);
$smarty->assign("partyName",$partyName);
$smarty->assign("isEdit",$isEdit);
$smarty->assign("viewArr",$viewArr);
$smarty->assign("editPartyId",$editPartyId);
$smarty->assign("editPartyName",$editPartyName);
$smarty->display('party.tpl');
?>